package J.算法.排序;

import java.util.ArrayList;
import java.util.TreeMap;

public class _1528_重新排列字符串 {
    /**
     * 自解：直接存到treemap里 直接排序
     * key- 存整形数组 value 存字符串
     * @param s
     * @param indices
     * @return
     */
    public String restoreString(String s, int[] indices) {
        TreeMap<Integer,Character> treeMap = new TreeMap<>();
        for (int i=0;i<s.length();i++){
            treeMap.put(indices[i],s.charAt(i) );
        }

        String string = "";
        for (Character character:treeMap.values()){
            string += character;
        }

        return string;

    }

    /**
     * 题解：直接利用index对应关系 rs【indict【i】】 = s.charAt[i]
     */
    public String restoreString1(String s, int[] indices) {
       char[] rs = new char[s.length()];
        for (int i  = 0;i<s.length();i++){
            rs[indices[i]] = s.charAt(i);
        }

        return String.valueOf(rs);
    }
}
